//
//  MapViewController.m
//  WE
//
//  Created by apple on 15/11/25.
//  Copyright © 2015年 UNOHACHA. All rights reserved.
//

#import "MapViewController.h"
#import "Size.h"
//#import "BNRoutePlanModel.h"
//#import "BNCoreServices.h"
//#import <BaiduMapAPI_Map/BMKMapView.h>
//#import <BaiduMapAPI_Map/BMKPinAnnotationView.h>
//#import <BaiduMapAPI_Map/BMKPointAnnotation.h>
//#import <BaiduMapAPI_Location/BMKLocationComponent.h>

@interface MapViewController ()
//<BMKMapViewDelegate,BNNaviRoutePlanDelegate,BNNaviUIManagerDelegate,BMKLocationServiceDelegate>

//@property (nonatomic, strong)BMKMapView *mapView;
//@property (nonatomic, strong)BMKLocationService *locService;
//@property (nonatomic, strong)

@end

@implementation MapViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.navigationItem.title = @"导航";
    self.view.backgroundColor = [UIColor whiteColor];
    /*
    self.mapView = [[BMKMapView alloc] initWithFrame:CGRectMake(0, 0, WindowWidth, WindowHeight - 49)];
    self.mapView.backgroundColor = [UIColor yellowColor];
    [_mapView setCenterCoordinate:CLLocationCoordinate2DMake(30.276951, 120.125042)animated:YES];
    _mapView.mapType = BMKMapTypeStandard;
    _mapView.tintColor = [UIColor blackColor];
    _mapView.compassPosition = CGPointMake(WindowWidth/2, (WindowHeight - 49)/2);
    _mapView.zoomLevel = 15;
    ///设定地图View能否支持用户多点缩放(双指)
   // @property(nonatomic, getter=isZoomEnabled) BOOL zoomEnabled;
    ///设定地图View能否支持用户缩放(双击或双指单击)
    //@property(nonatomic, getter=isZoomEnabledWithTap) BOOL zoomEnabledWithTap;
    ///设定地图View能否支持用户移动地图
   // @property(nonatomic, getter=isScrollEnabled) BOOL scrollEnabled;
    ///设定地图View能否支持俯仰角
  //  @property(nonatomic, getter=isOverlookEnabled) BOOL overlookEnabled;
    ///设定地图View能否支持旋转
   // @property(nonatomic, getter=isRotateEnabled) BOOL rotateEnabled;
    _mapView.zoomEnabled = YES;
    _mapView.showMapPoi = YES;
    _mapView.zoomEnabledWithTap = YES;
    _mapView.buildingsEnabled = YES;
    _mapView.showMapScaleBar = YES;
    _mapView.scrollEnabled = YES;
   //[self.view addSubview:_mapView];
    //初始化BMKLocationService
    _locService = [[BMKLocationService alloc]init];
    _locService.delegate = self;
    //启动LocationService
    [_locService startUserLocationService];
       [self setupView];
    //self.view= _mapView;
    
    [self.view addSubview:self.mapView];
     */
}

/*
- (BMKAnnotationView *)mapView:(BMKMapView *)mapView viewForAnnotation:(id <BMKAnnotation>)annotation
{
    if ([annotation isKindOfClass:[BMKPointAnnotation class]]) {
        BMKPinAnnotationView *newAnnotationView = [[BMKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"myAnnotation"];
        newAnnotationView.pinColor = BMKPinAnnotationColorPurple;
        newAnnotationView.animatesDrop = YES;// 设置该标注点动画显示
        return newAnnotationView;
    }
    return nil;
}
//处理方向变更信息
- (void)didUpdateUserHeading:(BMKUserLocation *)userLocation
{
    //NSLog(@"heading is %@",userLocation.heading);
}
//处理位置坐标更新
- (void)didUpdateBMKUserLocation:(BMKUserLocation *)userLocation
{
    
    _mapView.showsUserLocation = YES;//显示定位图层
    [_mapView updateLocationData:userLocation];
    NSLog(@"didUpdateUserLocation lat %f,long %f",userLocation.location.coordinate.latitude,userLocation.location.coordinate.longitude);
    _locService.delegate = nil;
}

- (void)viewWillAppear:(BOOL)animated{
    [_mapView viewWillAppear];
    BMKPointAnnotation* annotation = [[BMKPointAnnotation alloc]init];
    CLLocationCoordinate2D coor;
    coor.latitude = 30.276951;
    coor.longitude = 120.125042;
    annotation.coordinate = coor;
    annotation.title = @"这里是吾诺瀚卓";
    [_mapView addAnnotation:annotation];
    _mapView.delegate = self;
}

- (void)viewWillDisappear:(BOOL)animated{
    [_mapView viewWillDisappear];
    _mapView.delegate = nil;
}

- (void)setupView{
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, WindowHeight - 49, WindowWidth, WindowHeight - 49)];
    view.backgroundColor = [UIColor blackColor];
    view.alpha = 0.5;
    UILabel *nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(10*Width, 10, WindowWidth - 150, 29)];
    nameLabel.text = @"浙江肿瘤医院";
    nameLabel.textColor = [UIColor whiteColor];
    nameLabel.backgroundColor = [UIColor blackColor];
    [view addSubview:nameLabel];
    
    UIButton *navigationButton = [UIButton buttonWithType:UIButtonTypeCustom];
    navigationButton.frame = CGRectMake(WindowWidth - 55, 7, 50, 35);
//    [navigationButton setTitle:@"导航" forState:UIControlStateNormal];
    
    UILabel *nalabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 0, 30, 35)];
    nalabel.text = @"导航";
    nalabel.textAlignment = NSTextAlignmentCenter;
    nalabel.font = FONT(12);
    [navigationButton addSubview:nalabel];
   //navigationButton.titleLabel.font = FONT(12);
    //navigationButton.titleEdgeInsets = UIEdgeInsetsMake(5, 22, 0,5);
    [navigationButton setImage:[UIImage imageNamed:@"navition"] forState:UIControlStateNormal];
    //navigationButton.titleLabel.frame = CGRectMake(21, 5, 29, 25);
    navigationButton.imageEdgeInsets = UIEdgeInsetsMake(10, 8, 10, 30);
    [navigationButton addTarget:self action:@selector(pressNavigationButton) forControlEvents:UIControlEventTouchUpInside];
    navigationButton.backgroundColor = [UIColor whiteColor];
    [navigationButton setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
    [view addSubview:navigationButton];
    
    UIButton *phoneButton = [UIButton buttonWithType:UIButtonTypeCustom];
    phoneButton.frame = CGRectMake(WindowWidth - 110, 7, 50, 35);
    
    [phoneButton addTarget:self action:@selector(pressPhoneButton) forControlEvents:UIControlEventTouchUpInside];
    phoneButton.backgroundColor = [UIColor whiteColor];
    [phoneButton setImage:[UIImage imageNamed:@"phone"] forState:UIControlStateNormal];
    UILabel *phLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 0, 30, 35)];
    phLabel.text = @"电话";
    phLabel.font = FONT(12);
    phLabel.textAlignment = NSTextAlignmentCenter;
    [phoneButton addSubview:phLabel];
   // phoneButton.titleEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 0);
    phoneButton.imageEdgeInsets = UIEdgeInsetsMake(10, 8, 10, 30);
    [phoneButton setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
    [view addSubview:phoneButton];
    
    [self.view addSubview:view];
    
}
- (void)pressPhoneButton{
    
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel://8008808888"]];
    
}
 - (void)viewWillAppear:(BOOL)animated
 {
 self.navigationController.navigationBar.hidden = NO;
 
 }

- (void)pressNavigationButton{
    [self startNavi];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
//发起导航
- (void)startNavi
{
    //节点数组
    NSMutableArray *nodesArray = [[NSMutableArray alloc]    initWithCapacity:2];
    
    //起点
    BNRoutePlanNode *startNode = [[BNRoutePlanNode alloc] init];
    startNode.pos = [[BNPosition alloc] init];
    
    startNode.pos.x = 120.125042;
    startNode.pos.y = 30.276951;
    startNode.pos.eType = BNCoordinate_BaiduMapSDK;
    [nodesArray addObject:startNode];
    
    //终点
    BNRoutePlanNode *endNode = [[BNRoutePlanNode alloc] init];
    endNode.pos = [[BNPosition alloc] init];
    
    endNode.pos.x = 120.125042;
    endNode.pos.y = 31.276951;
    endNode.pos.eType = BNCoordinate_BaiduMapSDK;
    [nodesArray addObject:endNode];
    //发起路径规划
    [BNCoreServices_RoutePlan startNaviRoutePlan:BNRoutePlanMode_Recommend naviNodes:nodesArray time:nil delegete:self userInfo:nil];
}
//算路成功后，在回调函数中发起导航，如下：
//算路成功回调
-(void)routePlanDidFinished:(NSDictionary *)userInfo
{
    NSLog(@"算路成功");
    
    //路径规划成功，开始导航
    [BNCoreServices_UI showNaviUI: BN_NaviTypeReal delegete:self isNeedLandscape:YES];
}

#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}

*/
@end
